package tech.aistar.day09;

import tech.aistar.day09.homework.Purcase;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/7/29 8:49 上午
 */
public class ListSortDemo {
    public static void main(String[] args) {
        List<Purcase> lists = new ArrayList<>();
        Purcase p1 = new Purcase("宝洁","洗手粉",18.5);
        Purcase p2 = new Purcase("联合利华","肥皂",4.5);
        Purcase p3 = new Purcase("宝洁","牙膏",32.5);
        Purcase p4 = new Purcase("宝洁","毛巾",14.5);
        lists.add(p1);
        lists.add(p2);
        lists.add(p3);
        lists.add(p4);

        //lists.sort(new Comparator<Purcase>() {
        //    @Override
        //    public int compare(Purcase o1, Purcase o2) {
        //        //cost降序
        //        //return (int) (o2.getCost()-o1.getCost());
        //
        //        //返回正数,还是负数,0
        //        if(o2.getCost()>o1.getCost()){
        //            return 1;
        //        }else if(o2.getCost()<o1.getCost()){
        //            return -1;
        //        }
        //        return 0;//相等
        //
        //    }
        //});

        lists.sort((o1,o2)-> (int) (o2.getCost()-o1.getCost()));

        lists.forEach(e-> System.out.println(e));
    }
}
